#!/bin/python3
import os

if os.path.exists("notenogram.sav"):
	datasize = 18*3
	bitindex = 0
	savefile = open("notenogram.sav", "rb").read(datasize)
	datafile = open("notekeeper_output", "w")
	print("save found!")
	for i in range(3):
		while bitindex < datasize:
			puzzleindex = "constexpr bn::array<bool, 144> NotekeeperPuzzle_{}\n"
			datafile.write(puzzleindex.format(i))
			datafile.write("	{\n")
			for number in range(18):
				byterow = "		"
				byte = savefile[bitindex] 
				for bit in range(8):
					bitstring = "{}, "
					if bit == 7:
						if number == 17:
							bitstring = "{}\n"
						else:
							bitstring += "\n"
					byterow += bitstring.format((byte >> bit) & 1)
				datafile.write(byterow)
				bitindex += 1
			datafile.write("	};\n\n")
	datafile.close()
	print("puzzles converted!")
else:
	print("save not found!")

